<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/js/jquery-3.6.0.min.js"></script>
    <link href="../css/table.css" type="text/css" rel="stylesheet">
</head>
<body>

    <div th:include="common/inc"></div>

<!--        <input type="button" value="新增" onclick="toAddPosition()" >-->
    <div id="table2">
        <div id="login_click">
            <input id="b3" type="button" value="新增" class="pink" onclick="toAddPosition()" >
<!--            <a id="btlogin" onclick="toAddPosition()">新增</a>-->
        </div>
        <table style="width: 998px;" class="table">
            <caption style="width: 998px;text-align: center;">
                <h2 style="width: 998px;text-align: center;">职位招聘列表</h2>
            </caption>
            <thead>
            <tr>
                <th>职位名称</th>
                <th>学历要求</th>
                <th>工作经验</th>
                <th>薪资范围</th>
                <th>操作</th>
            </tr>
            </thead>
            <tr th:each="p:${position}">
                <td th:text="${p.positionName}"></td>
                <td th:text="${p.degree}"></td>
                <td th:text="${p.experience}"></td>
                <td th:text="${p.salary}"></td>
                <td >
                        <input id="b1" type="button" value="修改" class="orange" th:onclick="|updatePosition(${p.positionId})|" >
                        <input id="b2" type="button" value="删除" class="red" th:onclick="|deletePosition(${p.positionId})|" >
                </td>
            </tr>
        </table>
    </div>
<!--    <table border="1" style="">-->
<!--        <tr>-->

<!--            <td>职位名称</td>-->
<!--            <td>学历要求</td>-->
<!--            <td>工作经验</td>-->
<!--            <td>薪资范围</td>-->
<!--            <td>操作</td>-->
<!--        </tr>-->
<!--        <tr th:each="p:${position}">-->
<!--            <td th:text="${p.positionName}"></td>-->
<!--            <td th:text="${p.degree}"></td>-->
<!--            <td th:text="${p.experience}"></td>-->
<!--            <td th:text="${p.salary}"></td>-->
<!--            <td >-->
<!--                <div id="button1">-->
<!--                    <input id="b1" type="button" value="修改" th:onclick="|updatePosition(${p.positionId})|" >-->
<!--                    <input id="b2" type="button" value="删除" th:onclick="|deletePosition(${p.positionId})|" >-->
<!--                </div>-->
<!--            </td>-->
<!--        </tr>-->
<!--    </table>-->
</body>
<script>

    $(function(){

    })
    //初始化查询列表
    function getPosition(){
        $.ajax({
            url:"/position/getPosition",
            type:"post",
            dataType:"json",
            //data:$("form").serialize(),
            success:function (data){
                $("#list").val(data);
                //赋值报错
            },error:function (){
                alert("查询失败");
            }
        })
    }

    //跳转到新增页面
    function toAddPosition(){
        location.href="/position/toAddPosition";
    }

    //修改跳转
    function updatePosition(positionId){
        location.href="/position/toUpdatePosition?positionId="+positionId;
    }

    //删除数据
    function deletePosition(positionId){
        $.ajax({
            url:"/position/deletePosition",
            type:"post",
            data:{"positionId":positionId},
            success:function (){
                alert("删除成功");
                location.href="/position/position";//跳转
            },error:function () {
                alert("新增失败");
            }
        })
    }

</script>


</html>